'use strict';
const Controller = require('egg').Controller;

class yjController extends Controller {
    
    async comment() {
        // console.log(999999)
        //    let sql = `SELECT  * FROM  carinformation  ORDER  BY carid  DESC  LIMIT 9`   
        //    this.ctx.body=await this.app.mysql.query(sql)
        let query = this.ctx.query
        console.log(query, 111,query.content,query.user,query.book)

        let sql = `INSERT  INTO comments (content,  email,  bookID) VALUES('${query.content}','${query.user}', ${query.book})`

        let result = await this.app.mysql.query(sql)

        this.ctx.body = "返回数据"
    }
    async book() {

        let query = this.ctx.query
        // console.log(query, 111)

        let sql = `SELECT  *  FROM  book WHERE bookID=${query.bookID}; `

         this.ctx.body= await this.app.mysql.query(sql)
    }
    async chapter() {

        let query = this.ctx.query
       

        let sql = `SELECT  *  FROM  chapter WHERE bookID=${query.bookID}  ORDER  BY chapterTime  DESC  LIMIT 9  `
        
         this.ctx.body= await this.app.mysql.query(sql)
    }

    async comments() {

        let query = this.ctx.query
        // console.log(query, 111)
        let sql = `SELECT * FROM  comments left JOIN user on comments.email=user.email ORDER  BY comment_id  DESC ; `
        
         this.ctx.body= await this.app.mysql.query(sql)
    }

    
    async zuishu() {

        let query = this.ctx.query
        console.log(query, 22222)
        let sql2 = `SELECT  *  FROM  follow_books WHERE user_email='${query.user}'; `
        let result2= await this.app.mysql.query(sql2)
        // console.log(result2.book_id,6666)
        this.ctx.body=result2
        // let sql = `INSERT  INTO follow_books (book_id,  user_email) VALUES('${query.bookID}','${query.user}') ; `
        
        // let result= await this.app.mysql.query(sql)
        
    }

    async zuishu2() {

        let query = this.ctx.query
        console.log(query,15923156998)
       
        let sql = `INSERT  INTO follow_books (book_id,  user_email) VALUES('${query.bookID}','${query.user}') ; `
        
        let result= await this.app.mysql.query(sql)
        this.ctx.body="200"
        
    }
}


module.exports = yjController;
